/**
 * 
 */
package business.local.parser.util;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

/**
 * @author Skap3
 *
 */
public class ParserUtil {
	
	private static String RUTA_FICHERO = "";
	private static String NOMBRE_FICHERO = "";
	
	public static int parsearFichero (){
		try {
			BufferedReader bf = new BufferedReader(new FileReader(RUTA_FICHERO+NOMBRE_FICHERO));
			boolean sigue = true; 
			while (sigue){
				leerLinea (bf);
			}
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return -1;
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return -2;
		}
		return 1;
		

	}
	
	/**
	 * Lee una linea del fichero y extrae la info
	 * @param bf fichero abieto para lectura.
	 * @return objeto con la info extraida
	 */
	private static String leerLinea (BufferedReader bf) throws IOException{
		
		String lineaLeida = "";
		String[] divisorLinea;
		if (bf.ready()){
			lineaLeida = bf.readLine();
			if (lineaLeida!=null){
			if (lineaLeida.startsWith("+---")){
				//PRIMER NIVEL --> FANSUB
				lineaLeida.replaceAll("+---", "");
				divisorLinea = lineaLeida.split("]");
				System.out.println("FANSUB: "+divisorLinea[1]);
			} else if (lineaLeida.startsWith("|   +---")){
				//SEGUNDO NIVEL --> ANIME
				lineaLeida.replaceAll("|   +---", "");
				divisorLinea = lineaLeida.split("]");
				System.out.println("ANIME: "+divisorLinea[1]);
				
			} else {
				System.out.println("NADA");
			}
			} //else  
		}
		return null;
	}

}
